package com.example.softwareengg;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.StringTokenizer;



import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SlidingDrawer;
import android.widget.Toast;
import android.view.*;;

public class Screennot extends Activity {
	//String serverReply;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_listviewexampleactivity);
        
    final ListView listview = (ListView) findViewById(R.id.listview);
    String[] values = new String[] { "nishant requested for \"SE handout\"", "Yash uploaded \"placements.txt\"", "Dummy3000",
        "Dummy4", "Dummy5", "Dummy6", "Dummy7", "Dummy8",
        "Dummy9", "Dummy10", "Dummy11", "Dummy12", "Dummy13", "Dummy14",
        "Dummy15", "Dummy16", "Dummy17", "Dummy18", "Dummy19", "Dummy20",
        "Dummy21", "Dummy22", "Dummy23" };

    final ArrayList<String> list = new ArrayList<String>();
    
    	StringTokenizer addstring = new StringTokenizer(MyOverridenApp.getserverdata(),"$");
    	while(addstring.hasMoreTokens())
    	{
    	String nexttoken = addstring.nextToken();
    	MyOverridenApp.setfilenametobedownloaded(nexttoken);
      
      if(nexttoken.contains("since"))
	   {
    	  list.add("No new notifications. Click here to go back!");
	   }
      else
      {
    	  list.add(nexttoken);
    	 
      }

    }
    	
    
    //for(long k= 0;k<100000000;k++);
    
    
    final StableArrayAdapter adapter = new StableArrayAdapter(this,
        android.R.layout.simple_list_item_1, list);
    listview.setAdapter(adapter);

    listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {

    
    	
    		  @Override
    		  public void onItemClick(AdapterView<?> parent, View view,
    		    int position, long id) {
    		    //Toast.makeText(getApplicationContext(),
    		      //"Click ListItem Number " + position, Toast.LENGTH_LONG)
    		      //.show();
    		    
    		   String got =  listview.getItemAtPosition(position).toString();
    		   
    		   if(got.contains("upload"))
    		   {
    			  
    		   
    		    Intent intent2 = new Intent(Screennot.this, ScreenDownload.class);
			    startActivity(intent2);
			    
    		   }
    		   else if(got.contains("request"))
    		   {
    			   Intent intent3 = new Intent(Screennot.this, Screenout.class);
   			    startActivity(intent3);

    		   }
    		   else
    		   {
    			   Intent intent3 = new Intent(Screennot.this, ScreenB.class);
      			    startActivity(intent3);
    		   }

    		  }
    		}); 

    
  }

  private class StableArrayAdapter extends ArrayAdapter<String> {

    HashMap<String, Integer> mIdMap = new HashMap<String, Integer>();

    public StableArrayAdapter(Context context, int textViewResourceId,
        List<String> objects) {
      super(context, textViewResourceId, objects);
      for (int i = 0; i < objects.size(); ++i) {
        mIdMap.put(objects.get(i), i);
      }
    }

    @Override
    public long getItemId(int position) {
      String item = getItem(position);
      return mIdMap.get(item);
    }

    @Override
    public boolean hasStableIds() {
      return true;
    }

  }
} 